<% layout('/layouts/default.html', {title: 'dc_sup_task_group_unit管理', libs: ['validate','dataGrid']}){ %>
<div class="main-content">
	<div class="box box-main">
		<div class="box box-main">
			<div class="box-header">
				<#form:form id="searchForm"  model="${dcSupExamGroupUnit!}" action="${ctx}/exam/dcSupExamSumScoreResult/orgSelect?param=${param}" method="post" class="form-inline"
				data-page-no="${parameter.pageNo}" data-page-size="${parameter.pageSize}" data-order-by="${parameter.orderBy}">
				<div style="float: left">
					<div class="control-inline width-120">
						<% var items = [{label:'请选择',value:''},{label:'区县',value:'1'},{label:'市直',value:'2'}]; %>
						<#form:select path="orgType" items="${items}" itemLabel="label" itemValue="value"  class="form-control width-120 " />
					</div>
					<div class="control-inline width-320">
						<#form:input path="orgName" id="unitName" maxlength="200" class="form-control" oninput="request()"
						style="width:205px;" placeholder="请输入单位名称" autocomplete="off"/>
						<button type="submit" id="dd" class="btn btn-primary btn-sm">${text('查 询')}</button>
						<button type="reset" class="btn btn-default btn-sm">${text('重 置')}</button>
					</div>

				</div>

				<div style="float: right">
					<div class="form-group" >

						<button class="btn btn-primary btn-sm btnList" id="save">${text('保 存')}</button>
					</div>

				</div>
			</#form:form>
		</div>
		<div class="box-body">
			<table id="dataGrid"></table>
		</div>
	</div>
</div>
<% } %>
<script>
	$('#dataGrid').dataGrid({
		searchForm: $('#searchForm'),
		columnModel:[
			{header:'${text("主键")}', name:'id', hidden:true},
			{header:'${text("机构名称")}', name:'orgName',  width:150, align:"center"},
			{header:'${text("机构代码")}', name:'orgCode',  width:100, align:"center"},
			{header:'${text("序号")}', name:'orgSort',  width:100, align:"center"},
			{header:'${text("别名")}', name:'aliasName', hidden:true},
			{header:'${text("类型")}', name:'orgType', hidden:true},
			{header:'${text("常用组id")}', name:'groupId',  width:100, align:"center", hidden:true}
		],
		// 表格内没有数据的时候是否提示 “无数据显示”
		emptyDataHint: false,
		showCheckbox: true,
		onSelectRow:function (id, isSelect, event){
			if(event && event.target && !$(event.target).hasClass('cbox')){
				$('#dataGrid').dataGrid('setSelectRow', id, isSelect);
				return;
			}
		},
		// 是否显示行号
		showRownum: false,
		// 加载成功后执行事件
		ajaxSuccess: function(data){
			var ids = '${idRes}';
			if(ids){
			var idss = ids.split(",")
			for (let i = 0; i < idss.length; i++) {
				$('#dataGrid').dataGrid('setSelectRow', idss[i] , false);
			}

			}
		}
	});
	// 获取选择的组织机构
	function dataSelect(data) {
		let commitData = [];
		for (let key in data) {
			commitData.push($('#dataGrid').dataGrid('getRowData', data[key]));
		}
		return commitData;
	}
	// 非常用组使用进行 数据拼接处理返回
	function selectOrg(data){
		let orgCodeAndName=[];
		let orgCode=[];
		let orgName=[];
		let aliasName=[];
		let orgType=[];
		for(let key in data){
			orgCode.push(data[key].orgCode);
			orgName.push(data[key].orgName)
			aliasName.push(data[key].aliasName)
			orgType.push(data[key].orgType)
		}
		orgCodeAndName.push(orgCode);
		orgCodeAndName.push(orgName);
		orgCodeAndName.push(aliasName);
		orgCodeAndName.push(orgType);
		return orgCodeAndName;
	}
	$("#save").click(function (){
		let data = dataSelect($('#dataGrid').dataGrid('getSelectRows'));
			let orgSelect=selectOrg(data);
			// 根据赋值输入框id做定义   用作子页面向父页面传值
		$(window.parent.document).find("#noticeOrgNames").val(orgSelect[1]);
		$(window.parent.document).find("#noticeOrgs").val(orgSelect[0]);
		$(window.parent.document).find("#exameOrgNames").val(orgSelect[1]);
		$(window.parent.document).find("#exameOrgs").val(orgSelect[0]);
		$(window.parent.document).find("#orgType").val(orgSelect[0]);
		$(window.parent.document).find("#exameOrgName").val(orgSelect[1]);
		$(window.parent.document).find("#exameOrg").val(orgSelect[0]);
		var index = parent.layer.getFrameIndex(window.name);
		parent.layer.close(index);
	})
	function child(org,orgName) {


	}



</script>